home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.3 / Printer / src / Okimate20 / render.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  5.1 KB  |  201 lines

  1. /*
  2.     Okimate_20 driver.
  3.     David Berezowski - Sept/87.
  4.  
  5.   Copyright (c) 1988 Commodore-Amiga, Inc.
  6.  
  7.   Executables based on this information may be used in software
  8.   for Commodore Amiga computers.  All other rights reserved.
  9.  
  10.   This information is provided "as is"; no warranties are made.
  11.   All use is at your own risk, and no liability or responsibility is assumed.
  12. */
  13.  
  14.  
  15. #include <exec/types.h>
  16. #include <exec/nodes.h>
  17. #include <exec/lists.h>
  18. #include <exec/memory.h>
  19. #include "../printer/printer.h"
  20. #include "../printer/prtbase.h"
  21.  
  22. #define NUMSTARTCMD    5    /* # of cmd bytes before binary data */
  23. #define NUMENDCMD    1    /* # of cmd bytes after binary data */
  24. #define NUMTOTALCMD     (NUMSTARTCMD + NUMENDCMD)    /* total of above */
  25. #define NUMLFCMD    3    /* # of cmd bytes for linefeed */
  26. #define MAXCOLORBUFS    3    /* max # of color buffers */
  27.  
  28. Render(ct, x, y, status)
  29. long ct, x, y, status;
  30. {
  31.     extern void *AllocMem(), FreeMem();
  32.     extern struct PrinterData *PD;
  33.     extern struct PrinterExtendedData *PED;
  34.  
  35.     static UWORD RowSize, ColorSize, BufSize, TotalBufSize, dataoffset;
  36.     static UWORD colors[MAXCOLORBUFS]; /* color ptrs */
  37.     static UBYTE CRLF[] = "\033Jn";
  38.     static UWORD NumColorBufs; /* actually # of color buffers */
  39.     static UWORD NumSpcCmd; /* # of cmd bytes at very beginning */
  40.     UBYTE *ptr, *ptrstart, *ptr2, *ptr2start;
  41.     int i, err;
  42.  
  43.     switch(status) {
  44.         case 0 : /* Master Initialization */
  45.             /*
  46.                 ct    - pointer to IODRPReq structure.
  47.                 x    - width of printed picture in pixels.
  48.                 y    - height of printed picture in pixels.
  49.             */
  50.             RowSize = x * 3;
  51.             ColorSize = RowSize + NUMTOTALCMD;
  52.             if (PD->pd_Preferences.PrintShade == SHADE_COLOR) {
  53.                 NumColorBufs = MAXCOLORBUFS;
  54.                 NumSpcCmd = 2;
  55.             }
  56.             else {
  57.                 NumColorBufs = 1;
  58.                 NumSpcCmd = 0;
  59.             }
  60.             BufSize = NumSpcCmd + ColorSize * NumColorBufs +
  61.                 NUMLFCMD;
  62.             TotalBufSize = BufSize * 2;
  63.             for (i=0; i<NumColorBufs; i++) {
  64.                 colors[i] = ColorSize * i; /* YMC or B */
  65.             }
  66.             PD->pd_PrintBuf = AllocMem(TotalBufSize, MEMF_PUBLIC);
  67.             if (PD->pd_PrintBuf == NULL) {
  68.                 err = PDERR_BUFFERMEMORY; /* no mem */
  69.             }
  70.             else {
  71.                 dataoffset = NumSpcCmd + NUMSTARTCMD;
  72.                 if (PD->pd_Preferences.PrintShade ==
  73.                     SHADE_COLOR) {
  74.                     /* align ribbon (1st buffer) */
  75.                     *PD->pd_PrintBuf = 27;
  76.                     *(PD->pd_PrintBuf + 1) = 25;
  77.                     /* align ribbon (2nd buffer) */
  78.                     *(PD->pd_PrintBuf + BufSize) = 27;
  79.                     *(PD->pd_PrintBuf + BufSize + 1) = 25;
  80.                 }
  81.                 err = PDERR_NOERR; /* all ok */
  82.             }
  83.             break;
  84.  
  85.         case 1: /* Scale, Dither and Render */
  86.             /*
  87.                 ct    - pointer to PrtInfo structure.
  88.                 x    - 0.
  89.                 y    - row # (range 0 to Height - 1).
  90.             */
  91.             Transfer(ct, y, &PD->pd_PrintBuf[dataoffset], colors);
  92.             err = PDERR_NOERR; /* all ok */
  93.             break;
  94.  
  95.         case 2 : /* Dump Buffer to Printer */
  96.             /*
  97.                 ct    - 0.
  98.                 x    - 0.
  99.                 y    - # of rows sent (1 to NumRows).
  100.  
  101.                 White-space strip.
  102.             */
  103.             ptrstart = &PD->pd_PrintBuf[dataoffset];
  104.             ptr2 = ptrstart - NUMSTARTCMD;
  105.             ptr2start = ptr2 - NumSpcCmd;
  106.             x = 0; /* flag no transfer required yet */
  107.             for (ct=0; ct<NumColorBufs;
  108.                 ct++, ptrstart += ColorSize) {
  109.                 i = RowSize;
  110.                 ptr = ptrstart + i - 1;
  111.                 while (i > 0 && *ptr == 0) {
  112.                     i--;
  113.                     ptr--;
  114.                 }
  115.                 i = (i + 2) / 3;
  116.                 ptr = ptrstart - NUMSTARTCMD;
  117.                 *ptr++ = 27;
  118.                 *ptr++ = '%';
  119.                 *ptr++ ='O';        /* enter 24-dot mode */
  120.                 *ptr++ = i & 0xff;
  121.                 *ptr++ = i >> 8;    /* size */
  122.                 i *= 3;
  123.                 *(ptrstart + i) = 13; /* cr */
  124.                 i += NUMTOTALCMD;
  125.                 if (x != 0) { /* if must transfer data */
  126.                     /* get src start */
  127.                     ptr = ptrstart - NUMSTARTCMD;
  128.                     do { /* transfer and update dest ptr */
  129.                         *ptr2++ = *ptr++;
  130.                     } while (--i);
  131.                 }
  132.                 else { /* no transfer required */
  133.                     ptr2 += i; /* update dest ptr */
  134.                 }
  135.                 /* if compacted or 0 */
  136.                 if (i != RowSize + NUMTOTALCMD) {
  137.                     x = 1; /* we need to xfer next time */
  138.                 }
  139.             }
  140.             y += (y + 1) / 2; /* convert 144ths to 216ths */
  141.             *ptr2++ = 0x1b;
  142.             *ptr2++ = 'J';
  143.             *ptr2++ = y;    /* y/216 lf */
  144.             i = ptr2 - ptr2start; /* calc size */
  145.             /* if completely empty */
  146.             if (i == NumSpcCmd + NUMTOTALCMD * NumColorBufs +
  147.                 NUMLFCMD) {
  148.                 CRLF[2] = y;
  149.                 /* y/216 lf */
  150.                 err = (*(PD->pd_PWrite))(CRLF, NUMLFCMD);
  151.             }
  152.             else {
  153.                 err = (*(PD->pd_PWrite))(ptr2start, i);
  154.             }
  155.             if (err == PDERR_NOERR) {
  156.                 dataoffset = (dataoffset == NumSpcCmd +
  157.                     NUMSTARTCMD ? BufSize : 0) +
  158.                     NumSpcCmd + NUMSTARTCMD;
  159.             }
  160.             break;
  161.  
  162.         case 3 : /* Clear and Init Buffer */
  163.             /*
  164.                 ct    - 0.
  165.                 x    - 0.
  166.                 y    - 0.
  167.             */
  168.             ptr = &PD->pd_PrintBuf[dataoffset];
  169.             i = BufSize - NumSpcCmd - NUMTOTALCMD - NUMLFCMD;
  170.             do {
  171.                 *ptr++ = 0;
  172.             } while (--i);
  173.             err = PDERR_NOERR; /* all ok */
  174.             break;
  175.  
  176.         case 4 : /* Close Down */
  177.             /*
  178.                 ct    - error code.
  179.                 x    - io_Special flag from IODRPReq struct.
  180.                 y    - 0.
  181.             */
  182.               /* wait for both buffers to empty */
  183.             (*(PD->pd_PBothReady))();
  184.             if (PD->pd_PrintBuf != NULL) {
  185.                 FreeMem(PD->pd_PrintBuf, TotalBufSize);
  186.             }
  187.             err = PDERR_NOERR; /* all ok */
  188.             break;
  189.  
  190.         case 5 : /* Pre-Master Initialization */
  191.             /*
  192.                 ct    - 0 or pointer to IODRPReq structure.
  193.                 x    - io_Special flag from IODRPReq struct.
  194.                 y    - 0.
  195.             */
  196.             err = PDERR_NOERR; /* all ok */
  197.             break;
  198.     }
  199.     return(err);
  200. }
  201.